<!--
 * @Date: 2023-03-21 15:54:12
 * @LastEditTime: 2023-09-18 14:01:28
 * @FilePath: /wkw/src/tabbar/me/index.vue
 * 介绍:我的
-->
<script lang="ts" setup name="me">
import { addCache } from "@@/hooks/routeCache";
import { _require } from "@@/utils/tools";
import type CpageView from "@@/components/common/CpageView/CpageView.vue";
import useUserinfoStore from "@@/store/useUserinfoStore";
import linkCells from "./components/linkCells.vue";
import { numThousand, omitText } from "@@/utils/tools/format";
import { fixedDecimals } from "@@/utils/tools/format";
import useBalanceStore from "@@/store/useBalanceStore";
import { sysLoad } from "@@/hooks/sysHooks";
import { levelEnum } from "@@/enum/globalEnum";

const userinfoStore = useUserinfoStore();
userinfoStore.getWalletName();
const balanceStore = useBalanceStore();
const WKC = computed(() => balanceStore.getCoinByCode("WKC"));
const USDT = computed(() => balanceStore.getCoinByCode("USDT"));

const { walletName, address, userinfo } = storeToRefs(userinfoStore);

const CpageViewRef = ref<InstanceType<typeof CpageView>>();

addCache("me");

sysLoad(onRefresh);
async function onRefresh() {
  CpageViewRef.value?.pullRefreshStart();
  await Promise.all([
    userinfoStore.getUserinfo(),
    userinfoStore.getWalletName(),
    balanceStore.findBalance(USDT.value),
    balanceStore.findBalance(WKC.value),
  ]);
  CpageViewRef.value?.pullRefreshSuccess();
}
</script>

<template>
  <CpageView ref="CpageViewRef" @refresh="onRefresh" pull-refresh>
    <Ccard>
      <div class="flex-A-C flex-J-SB">
        <div>
          <h2>
            {{ walletName }}
          </h2>
          <CcopyText class="MT-xs C-T3" :copy-text="userinfo?.address">
            {{ omitText(userinfo?.address) }}
          </CcopyText>
        </div>
        <BwkLevel :level="userinfo?.level" />
      </div>
      <VanDivider class="MT-md MB-md" />
      <div class="flex-J-SB MT-lg">
        <div class="flex-1">
          <div class="C-T3">{{ WKC?.code }}</div>
          <h3 class="MT-xs">{{ numThousand(fixedDecimals(WKC?.balance)) }}</h3>
        </div>
        <VanDivider class="ML-xl MR-xl" vertical style="height: auto" />
        <div class="flex-1">
          <div class="C-T3">{{ USDT?.code }}</div>
          <h3 class="MT-xs">{{ numThousand(fixedDecimals(USDT?.balance)) }}</h3>
        </div>
      </div>
      <Rbutton
        class="MT-lg"
        :size="'large'"
        round
        bg="var(--C-LG1)" borderStyle="none"
        v-if="userinfo?.register_task.is_robot"
        @click="$router.push({ name: 'me-myTask' })"
      >
        <div class="T-A-C">{{ $t("wo-de-reng-wu") }}</div>
      </Rbutton>
      <Rbutton
        class="MT-lg"
        :size="'large'"
        round
        bg="var(--C-LG1)" borderStyle="none"
        v-else
        @click="$router.push({ name: 'me-unlockReward' })"
      >
        <div class="T-A-C">{{ $t("ling-qu-jiang-li") }}</div>
      </Rbutton>
    </Ccard>
    <linkCells />
  </CpageView>
</template>

<style lang="scss" scoped></style>
